//
//  BSStatusCell.swift
//  mySwiftWeibo
//
//  Created by apple on 16/7/30.
//  Copyright © 2016年 shengqingwei. All rights reserved.
//

import UIKit

/// 微博cell, 包含 原创View, 被转发View,底部按钮View
class BSStatusCell: UITableViewCell {
    
    ///微博模型
    var status: BSStatus?{
        didSet{
            //拿到模型,赋值给originalView
            originalView.status=status
            
            //被转发微博模型
            retweetView.retweeted_status = status?.retweeted_status
        }
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
  
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        setupUI()
    }

    ///设置UI界面
    private func setupUI(){
        
        //背景颜色
        self.contentView.backgroundColor = UIColor(white: 237.0 / 255.0, alpha: 1)
        
        //添加
        self.contentView.addSubview(originalView)
        self.contentView.addSubview(retweetView)
        self.contentView.addSubview(bottomView)
        
        //约束
        originalView.snp_makeConstraints { (make) -> Void in
            make.leading.trailing.equalTo(self.contentView)
            make.top.equalTo(self.contentView).offset(CellMargin)
            
            //模拟高度
            //let height = CGFloat(arc4random_uniform(60)) + 44
            //make.height.equalTo(height)
        }
        
        //被转发微博的view
        retweetView.snp_makeConstraints { (make) -> Void in
            make.leading.trailing.equalTo(self.contentView)
            make.top.equalTo(originalView.snp_bottom)
        }
        
        //bottomview
        bottomView.snp_makeConstraints { (make) -> Void in
            make.leading.trailing.equalTo(self.contentView)
            make.top.equalTo(retweetView.snp_bottom)
            make.height.equalTo(37)
        }
        
        //让cell的高度自己适应,实际是根据contentview的高度来
        //所以需要约束好contentview
        self.contentView.snp_makeConstraints { (make) -> Void in
            make.leading.top.trailing.equalTo(self)
        }
        
        //contentview的高度
        self.contentView.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(bottomView)
        }
    }
    
    //MARK: - 懒加载
    private lazy var originalView: BSStatusOriginalView=BSStatusOriginalView()
    
    ///被转发微博view
    private lazy var retweetView: BSStatusRetweetView=BSStatusRetweetView()
    
    private lazy var bottomView: BSStatusBottomView=BSStatusBottomView()

}
